#!/usr/bin/python3

import sys
import cgi


fs = cgi.FieldStorage()

for key in fs.keys():
    data = fs[key]
    if getattr(data, '_binary_file', None) and data.filename:
        filename = data.filename
        ofile = open('/tmp/upload_%s' % filename, 'wb')
        while True:
            chunk = data.file.read(5)
            if not chunk:
                break
            ofile.write(chunk)

print('Content-Type: text/plain\n\n', end='')
print('uploaded %s bytes' % total)
